import { datas } from './fields.js'
let that
// 串口监听
export default {
	data() {
		return {
			num: 0,
			// 仪器列表
			lists: [],
			// 仪器类型id
			id: 0,
			nodata:false,
			deviceTypeList: [],
			selectedItem: '请选择仪器类型',
			equipList:[],
			selectedEquipItem:'请选择仪器所在设备',
			// 仪器所在设备id
			equipId:0,
			
		}
	},
	computed: {},
	onShow() {
		that = this
		that.getDeviceList()
	},
	created() {
		that = this
	},
	onReady() {},
	onLoad(options) {
		that = this
		uni.request({
			url: '/api/h5/getDeviceTypeList',
			method: "POST",
			header: {},
			data: {},
			success: (res) => {
				that.deviceTypeList = res.data.data
				const allType = {id:null,typeName:'全部'}
				that.deviceTypeList.unshift(allType)
			},
			fail: (err) => {
				console.error(err);
			}
		});
		
		uni.request({
			url: '/api/h5/getEquiList',
			method: "POST",
			header: {},
			data: {},
			success: (res) => {
				that.equipList = res.data.data
			},
			fail: (err) => {
				console.error(err);
			}
		});
		
	},
	methods: {
		changeInfo(item) {
			uni.setStorageSync("deviceInfo", item)
			uni.navigateTo({
				url: "/pages/device/details/index"
			})
		},
		getDeviceList() {
			uni.request({
				url: '/api/h5/getDeviceListBorrow',
				method: "POST",
				header: {},
				data: {
					"typeId": that.id,
					"equipId": that.equipId
				},
				success: (res) => {
					that.lists = res.data.data
					if(that.lists.length == 0){
						that.nodata = true
					}else{
						that.nodata = false
					}
				},
				fail: (err) => {
					console.error(err);
				}
			});
		},
		// 选择仪器类型
		onPickerChange(e) {
			that.selectedItem = that.deviceTypeList[e.detail.value]['typeName']
			that.id = that.deviceTypeList[e.detail.value]['id']
			that.getDeviceList()
		},
		
		// 选择仪器所在设备
		onEquiPickerChange(e) {
			that.selectedEquipItem = that.equipList[e.detail.value]['equiName']
			that.equipId = that.equipList[e.detail.value]['id']
			that.getDeviceList()
		},
	}
}